if (!kwok) var kwok = {};
if (!kwok.locationbarlimit) kwok.locationbarlimit = {};

kwok.locationbarlimit =
{
	prefs: Components.classes["@mozilla.org/preferences-service;1"]
			.getService(Components.interfaces.nsIPrefService)
			.getBranch("extensions.locationbarlimit."),
		
	/*
	 * Initialise locationbar limit.
	 */
	init: function()
	{
		//this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
		//	.getService(Components.interfaces.nsIPrefService)
		//	.getBranch("extensions.locationbarlimit.");
		kwok.locationbarlimit.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
		//kwok.locationbarlimit.prefs.addObserver("", this, false);
		
		kwok.locationbarlimit.load();
	},
		
	/*
	 * Loads settings from the preference.
	 */
	load: function()
	{
		var max = 999;
		var limit = this.prefs.getIntPref("maxrows");
		
		if (limit > 0)
		{
			max = limit;
		}
		
		var windowsEnum = Components.classes["@mozilla.org/appshell/window-mediator;1"]
			.getService(Components.interfaces.nsIWindowMediator)
			.getEnumerator("navigator:browser");
		
		while (windowsEnum.hasMoreElements())
		{
			var win = windowsEnum.getNext();
			var urlbar = win.document.getElementById("urlbar");
			urlbar.setAttribute("maxrows", max);
		}
	},
	
	// /*
	 // * Called whenever the setting changes.
	 // */
	// observe: function(subject, topic, data)
	// {
		// if (topic == "nsPref:changed")
		// {
			// kwok.locationbarlimit.load();
		// }
	// },
}

window.addEventListener("load", kwok.locationbarlimit.init, false);